package com.wang.config;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.kevinsawicki.http.HttpRequest;
import com.wang.code.dao.JijinRepository;
import com.wang.code.entity.JijinDO;
import com.wang.code.service.JIJinService;
import com.wang.constants.SystemParam;
import com.wang.entity.JijinVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * @Author wanglei
 * @Date 2019/11/28 9:15
 * @Version V1.0
 **/
@Component
public class UpdateScheduling {

    @Autowired
    private JIJinService jiJinService;
    @Autowired
    private JijinRepository jijinRepository;

    // 一分钟执行一次
    @Scheduled(fixedRate = 1000 * 60)
    public void update() {
        List<JijinDO> all = jijinRepository.findAll();
        if (CollUtil.isEmpty(all)) {
            return;
        }

        for (JijinDO jijinDO : all) {
            JijinVO jijinVO = jiJinService.newData(jijinDO.getCode());
            jijinDO.setGszzl(jijinVO.getGszzl());
            jijinDO.setGsz(new BigDecimal(jijinVO.getGsz()));
        }
        jijinRepository.saveAll(all);
    }

}
